/*
 * @Descripttion: 
 * @Author: cuidm
 * @Date: 2022-08-02 10:27:44
 * @LastEditors: cuidm
 * @LastEditTime: 2022-08-11 10:04:41
 */
import { useState, useEffect } from 'react';
import cmdbres from '@/data/cmdbres';
import request from '../../utils/request';
export async function queryModelAssociateMapping() {
    try {
        let res = await request({
            ...cmdbres.queryModelAssociateMapping,
        });
        if (res && res.code == 200) {
            return res.data.mapping||[]
        }
        return [];
    } catch (error) {
        console.log(error);
        return [];
    }
}

function useModelAssociateMapping() {
    const [loading, setLoading] = useState(false);
    const [data, setData] = useState([]);

    useEffect(() => {
        setLoading(true);
        setData([]);
        queryModelAssociateMapping()
            .then((res) => {
                setLoading(false);
                setData(res);
            })
            .catch((e) => {
                setLoading(false);
                setData([]);
                throw e;
            });
    }, []);
    return [data, loading];
}

export default useModelAssociateMapping;

